package admin.code.generator.util;

/**
 *
 *类名构造器
 *@author Jack
 *2016年3月4日下午11:43:47
 */
public class ClassNameMaker {
	private String tableName;

	public ClassNameMaker(String tableName) {
		this.tableName = tableName;
	}

	/**
	 * 获取类名
	 * @return
	 */
	public String makeClassName() {
		String nameStr = tableName;
		if (tableName.startsWith("t_")) {
			nameStr = nameStr.substring(2, tableName.length());
		}
		return buildClassName(nameStr);
	}

	/**
	 * 首字母小写的类名-->ControllerMappingValue
	 * @return
	 */
	public String controllerMappingVlaue() {
		String className = makeClassName();
		return Character.toLowerCase(className.charAt(0)) + className.substring(1, className.length());
	}

	/**
	 * 表名转换为类名 aaa_bbb ---> AaaBbb
	 * 遵从驼峰命名
	 * @param nameStr
	 * @return
	 */
	private String buildClassName(String nameStr) {
		StringBuilder className = new StringBuilder();
		String[] strs = nameStr.split("_");
		for (String str : strs) {
			className.append(Character.toUpperCase(str.charAt(0)))//首字母大写
					.append(str.substring(1, str.length()));//
		}
		return className.toString();
	}

	public String makeServiceClassName() {
		return makeClassName() + "Service";
	}

	public String makeServiceImplClassName() {
		return makeClassName() + "ServiceImpl";
	}

	public String makeDaoClassName() {
		return makeClassName() + "Dao";
	}

	public String makeDaoImpClassName() {
		return makeClassName() + "DaoImpl";
	}

	public String makeControllerClassName() {
		return makeClassName() + "Controller";
	}
}
